import 'package:flutter/services.dart';
import 'package:flutter_module/beans/data_layer_bean.dart';
import 'package:flutter_module/beans/element_bean.dart';
import 'package:flutter_module/system/log_util.dart';

import 'ni_data_method_id.dart';

class NIDataLayerDispatcher {
  static const _tag = 'NIDataLayerDispatcher';

  ///创建数据图层
  Future<bool> createDataLayer(
      MethodChannel _dataChannel, DataLayer layer) async {
    LogUtil.instance.printf("${layer.toMap()}");
    return await _dataChannel.invokeMethod(
        NIDataLayerMethodId.kDataCreateDataLayer, layer.toMap());
  }

  ///获取全部数据图层列表
  Future<List<DataLayer>> queryDataLayerList(MethodChannel _dataChannel) async {
    List<DataLayer> list = [];
    var res = await _dataChannel
        .invokeMethod(NIDataLayerMethodId.kDataGetDataLayerList);
    if (res is List) {
      for (var map in res) {
        if (map is Map) {
          list.add(DataLayer.from(map));
        }
      }
    }
    return list;
  }

  ///获取数据图层列表
  Future<DataLayer?> queryDataLayer(
      MethodChannel _dataChannel, String layerId) async {
    var res = await _dataChannel.invokeMethod(
        NIDataLayerMethodId.kDataGetDataLayer, layerId);
    return DataLayer.from(res);
  }
}
